package cn.com.headfree.sysmenu.controller;

import cn.com.headfree.base.controller.ExBaseController;
import cn.com.headfree.base.controller.ResultData;
import cn.com.headfree.entity.TOrgDept;
import cn.com.headfree.entity.isc.User;
import cn.com.headfree.sysmenu.service.IDeptUserService;
import cn.com.headfree.sysmenu.service.IRoleService;
import cn.com.headfree.sysmenu.vo.OrgDeptVo;
import cn.com.headfree.sysmenu.vo.TreeSelect;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

//部门人员信息
@Api(value = "部门人员信息",tags = {"部门人员信息接口"})//描述controller
@RestController
@RequestMapping(value = "/deptUser", produces = "application/json;charset=UTF-8")
public class DeptUserController extends ExBaseController {
    private static final Logger LOG = LogManager.getLogger(DeptUserController.class);

    @Autowired
    IRoleService roleService;

    @Autowired
    IDeptUserService deptUserService;

    /**
     * 查询单位树信息
     */
    @ApiOperation(value = "加载单位树信息列表",notes = "加载单位树信息列表",httpMethod = "POST")//描述接口
    @ApiImplicitParam(name = "orgDept", value = "entity", required = false, dataType = "OrgDeptVo")
    @RequestMapping("/getDeptUserTree")
    public ResultData getDeptUserTree(@RequestBody OrgDeptVo orgDept, HttpServletRequest req) {
        ResultData result = new ResultData();
        try {
            User user = getLoginUserInfo(req);
            List<OrgDeptVo> list = deptUserService.searchDeptList(orgDept, user);
            List<TreeSelect> menus = deptUserService.buildMenuTreeSelect(list);
            result.setData(menus);
            LOG.info("查询单位树信息成功");
        } catch (Exception e) {
            result.setErrorMsg("查询单位树信息异常");
            result.setSuccess(false);
            LOG.error("查询单位树信息异常", e);
        }
        return result;
    }



}
